﻿using LuShanTea.Service.Entities;
using System;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LuShanTea.Service.ModelConfig
{
    class RoleConfig : EntityTypeConfiguration<Role>
    {
        public RoleConfig()
        {
            this.ToTable("T_Roles");

            HasMany(r => r.Permissions).WithMany(p => p.Roles).Map(
                m => m.ToTable("T_RolePermissions").MapLeftKey("RoleId").MapRightKey("PermissionId")
                );

            //角色管理员关系表
            HasMany(r => r.AdminUsers).WithMany(a => a.Roles).Map(
               m => m.ToTable("T_AdminUserRoles").MapLeftKey("RoleId").MapRightKey("AminUserId")
               );

            Property(r => r.Name).IsRequired().HasMaxLength(64);
        }
    }
}
